package com.gexiao.config;

import com.gexiao.bean.Person;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;

//配置类==配置文件
@Configuration
//扫描扫描@Component，包括它的派生注解标注的类
//includeFilters：包含哪些包扫描
//excludeFilters：排除哪些包扫描

//@ComponentScan(value = "com.gexiao",excludeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class,Service.class}
//        )}
//)
@ComponentScan(value = "com.gexiao",
               includeFilters = {
                     // FilterType.ANNOTATION：按照注解
                     // FilterType.ASSIGNABLE_TYPE：按照指定的类型
                     // FilterType.CUSTOM：按照自定义的TypeFilter类型
                     // FilterType.REGEX：按照自定义的正则表达式过滤
//                   @Filter(type = FilterType.ANNOTATION,classes = {Controller.class,Service.class}),
//                   @Filter(type = FilterType.ASSIGNABLE_TYPE,classes = DemoDao.class),
//                   @Filter(type = FilterType.CUSTOM,classes = MyTypeFilter.class),
                     @Filter(type = FilterType.REGEX,pattern = ".*er*")
               },
               useDefaultFilters = false
)
public class MainConfig {

    // 等同于传统模式声明的<bean></bean>
    // 默认以方法名作为实例id
    @Bean("person001")
    public Person person() {
        return new Person("lisi", 17);
    }
}
